from django.db import models
from datetime import datetime


class Users(models.Model):
    id = models.AutoField(max_length=11, primary_key=True)
    did = models.CharField(max_length=64, unique=True)
    amount = models.IntegerField(max_length=11, blank=True, default=0)

    class Meta:
        db_table = 'users'

    def to_dict(self):
        return dict(
            id=self.id,
            did=self.did,
            amount=self.amount,
            data=datetime.now().strftime('%Y-%m-%d %H:%M:%S')
        )


class RechargeCard(models.Model):
    id = models.AutoField(max_length=11, primary_key=True)
    card_no = models.CharField(max_length=64, unique=True)
    state = models.IntegerField(max_length=11, default=0)
    amount = models.IntegerField(max_length=11)
    did = models.CharField(max_length=64, unique=True)

    class Meta:
        db_table = 'recharge_card'





class Notice(models.Model):
    id = models.AutoField(max_length=11, primary_key=True)
    title = models.CharField(max_length=512, blank=True)
    url = models.CharField(max_length=512, blank=True)

    def to_dict(self):
        return dict(
            title=self.title,
            url=self.url,
        )

    class Meta:
        db_table = 'notice'
